Embedding LaTeX equations into a webpage

您所在的位置:网站首页 about latex and mathml support in pages Embedding LaTeX equations into a webpage

Embedding LaTeX equations into a webpage

2023-09-08 13:02| 来源: 网络整理| 查看: 265

When embedding mathematics into a webpage, there are two primary questions:

What format should be used to display it? Where should the conversion be done?

In my opinion, each of these has a definite answer and a different solution should only be used if the optimal solution really cannot be done.

MathML. Reasons:

It is the only accessible way of doing this. Putting the original LaTeX in an alt tag on an image is not accessible - it relies on the recipient being able to understand raw LaTeX source code (more on this in a moment). Also, not all of those requiring accessible webpages use screen readers, some simply need to enlarge the page. It is styleable (not sure if that's a word). Since MathML is part of the XHTML suite, it can be styled in the same fashion as the rest of the document (namely, via CSS), so the resulting display is far more harmonious than any other (try changing the background colour to something easier on the eyes at one of those wordpress blogs and you'll see what I mean). It is small. A quick test on my system with 515 simple files that I happened to have lying around showed that PNGs weighed in at 175kB whilst the MathML equivalents were a shade under 60kB. The PNGs were not large resolution, for example the PNG containing the Zeta symbol was a 9x13 image.

Server-side. Reasons:

It is small. Instead of sending both the source and the instructions on how to compile it, you just send the result. It is reliable. You can easily check that what you want the person to see is what they should see. In particular, a javascript solution relies on two things being correct: the javascript script and the implementation of javascript in the browser. MathML just relies on the MathML implementation in the browser. It is fast. With server-side caching, you only need to process the mathematics once and then it's done. It is verifiable (similar to reliable, I guess). I don't fully understand the differences between the types of spec that w3c produce, but MathML is certainly a recommendation. Even though browser support is variable, the variations are known because they can be measured using the open standard, and thus can be taken into account.

Server-side MathML is the optimal solution. Of course, it's not always possible and then other solutions are useful.

There are various standard arguments against using server-side MathML and other myths about mathematics in webpages that are worth taking a minute over.

Myths

Sending the raw LaTeX code in an alt tag makes images accessible.

When people say this, they mean that they can read $a^2 + b^2 = c^2$ and understand it. Try them on something a little more complicated and you'll soon see that this is complete rubbish. For example, try having someone read out the following to you: $\begin{array}\ell^0(\mathbb{R})&\;\mapsto&\;\ell^2(\mathbb{R})\\\downarrow&&\uparrow\\L^2(\mathbb{R})&\subseteq\,&L^\infty(\mathbb{R})\end{array}$. Of course, there's going to be people who will say, "I can understand that!" but that's not the point. You write a webpage for other people and the more complicated the LaTeX, the fewer the number of people who can instantly read it.

MathML is badly supported.

This is the classic chicken-and-egg. MathML support is absolutely fine in Firefox, in IE with the MathPlayer plugin, and in Amaya (what's that?, I hear you cry!). Plus there are groups working on it for Opera and WebKit who just need a little encouragement! Sending them an email saying, "I love your browser but until it has proper MathML support then I can't use it" would provide them with a little more motivation. Of course, there are bugs in the implementations in Firefox and the others, but those are known and so can be worked around.

MathML requires documents to be valid XHTML.

Actually, this isn't a myth. It's absolutely true. But surely your pages were valid to begin with! I'm a mathematician and my ideal document is one that cannot be misunderstood. That's impossible, so I try for the lesser goal of where any misunderstanding can be laid at the door of the person reading it rather than me. MathML, as it's an open standard, allows me to reach that goal on webpages - at least technically, the contents are more variable!

Finally - on this part - for those that still worry about Joe Blogs (or Ola Nordmann, to be geographically correct) not being able to read your webpage due to using an old version of IE and refusing to install plugins, it is actually possible to have two versions of the mathematics on your server and send MathML to those that can see it and PNGs to those that can't, thus getting the best of both worlds.

What about implementation? Well, there you're in luck. iTeX can do it all, and in spades. iTeX is a fast c++ program that converts a subset of LaTeX mathematical language into MathML. The original package comes with bindings for ruby, and I've extended this to PHP, Perl, and Python. By combining it with other packages, in particular svgmath or gtkmathview, it is possible to further convert the MathML to an image for broken browsers. (Contact me for these extensions; I haven't gotten round to writing them up yet - it's on my TODO list!)

For examples, see the nlab (pure MathML) and the nforum (MathML, SVG, or PNG depending on what browser you are using).

Lastly, although I'm concerned with accessibility, I'm not an expert. So I've cross-posted my answer to the blindmath mailing list and shall update this according to the response that I get there.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3